package org.budo.validation.validator.factory;

import java.util.HashMap;
import java.util.Map;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

import org.budo.validation.validator.BudoValidator;
import org.budo.validation.validator.impl.LengthValidator;
import org.budo.validation.validator.impl.MaxValidator;
import org.budo.validation.validator.impl.MinValidator;
import org.budo.validation.validator.impl.NotBlankValidator;
import org.budo.validation.validator.impl.NotEmptyValidator;
import org.budo.validation.validator.impl.NotNullValidator;
import org.budo.validation.validator.impl.PatternValidator;
import org.budo.validation.validator.impl.SizeValidator;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;
import org.hibernate.validator.constraints.NotEmpty;

/**
 * @author lmw
 */
public class BudoValidatorFactory {
    private Map<Class<?>, BudoValidator> validatorMap = new HashMap<Class<?>, BudoValidator>();

    public BudoValidatorFactory() {
        validatorMap.put(NotNull.class, new NotNullValidator());
        validatorMap.put(Length.class, new LengthValidator());
        validatorMap.put(Max.class, new MaxValidator());
        validatorMap.put(Min.class, new MinValidator());
        validatorMap.put(Pattern.class, new PatternValidator());
        validatorMap.put(Size.class, new SizeValidator());
        validatorMap.put(NotBlank.class, new NotBlankValidator());
        validatorMap.put(NotEmpty.class, new NotEmptyValidator());
    }

    public BudoValidator getValidator(Class<?> annotationType) {
        return validatorMap.get(annotationType);
    }
}